<template>
  <el-container style="height: 700px; border: 1px solid #eee">
    <el-aside width="200px" style="background-color: rgb(238, 241, 246)">
      <el-menu :default-openeds="['1', '3']">
        <el-submenu index="1">
          <template slot="title"
            ><i class="el-icon-message"></i>数据管理</template
          >

          <el-menu-item index="1-4-1">
            <router-link to="/emp">员工管理</router-link>
          </el-menu-item>
          <el-menu-item index="1-4-1">
            <router-link to="/dept">部门管理</router-link>
          </el-menu-item>
          <el-menu-item index="1-4-1">
            <router-link to="/user">用户管理</router-link>
          </el-menu-item>

          <el-menu-item index="1-4-1">
            <router-link to="/role">角色管理</router-link>
          </el-menu-item>

          <el-menu-item index="1-4-1">
            <router-link to="/menu">菜单管理</router-link>
          </el-menu-item>
        </el-submenu>
      </el-menu>
    </el-aside>

    <el-container>
      <el-header style="text-align: right; font-size: 12px">
        <span v-text="username"> </span>
        <button @click="logout">注销</button>
      </el-header>
      <el-main>
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      username: "toString",
    };
  },
  mounted() {
    this.getUserInfo();
  },
  methods: {
    logout() {
      localStorage.removeItem("token");
      this.$router.push("/login");
    },
    getUserInfo() {
      let app = this;
      this.http
        .request({
          url: "userInfo",
          method: "GET",
        })
        .then(({ data }) => {
          if (data.code == 200) {
            app.username = data.data.username;
          }
        });
    },
  },
};
</script>

<style>
.el-header {
  background-color: #b3c0d1;
  color: #333;
  line-height: 60px;
}

.el-aside {
  color: #333;
}
</style>